﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;

namespace BlueRoseGames.Controls.Text
{
    public class SegmentPool
    {
        private static SegmentPool instance = null;
        Stack<QuadraticBezierSegment> quads;
        Stack<LineSegment> lines;

        public static SegmentPool Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new SegmentPool();
                }
                return instance;
            }
        }

        public SegmentPool()
        {
            quads = new Stack<QuadraticBezierSegment>();
            lines = new Stack<LineSegment>();
        }

        public LineSegment GetLineSegment()
        {
            if (lines.Count > 0)
            {
                return lines.Pop();
            }
            else
            {
                return new LineSegment();
            }
        }

        public QuadraticBezierSegment GetQuadraticBezierSegment()
        {
            if (quads.Count > 0)
            {
                return quads.Pop();
            }
            else
            {
                return new QuadraticBezierSegment();
            }
        }

        public void AddSegment(PathSegment s)
        {
            if (s is LineSegment)
            {
                AddLineSegment(s as LineSegment);
            }
            else if (s is QuadraticBezierSegment)
            {
                AddQuadraticBezierSegment(s as QuadraticBezierSegment);
            }
        }

        public void AddQuadraticBezierSegment(QuadraticBezierSegment quad)
        {
            quads.Push(quad);
        }

        public void AddLineSegment(LineSegment line)
        {
            lines.Push(line);
        }
    }
}
